package org.realogic.cfm.spring;


import java.sql.Timestamp;

import org.springframework.core.convert.converter.Converter;

public class StringToSqlTimestampConverter implements Converter<String, Timestamp> {

	public Timestamp convert(String value) {
		Timestamp temp = null;
		if (value != null && !value.trim().equals("") && !value.equals("null")) {
			value = value.trim();
			try {
				if(value.length()>=19){
					temp = Timestamp.valueOf(value);
				}
				else if(value.length()==16){
					temp = Timestamp.valueOf(value+":00");
				}
				else if(value.length()==10){
					temp = Timestamp.valueOf(value+" 00:00:00");
				}
				else{
					temp = null;
				}
			} catch (Exception e) {
				temp = null;
			}
		}
		return temp;

	}
	
	public static void main(String args[]){
		System.out.println(new java.sql.Timestamp(System.currentTimeMillis()));
		
		System.out.println("10:56".length());
	}
}
